package com.huabo.system.oracle.mapper;

import com.huabo.system.oracle.entity.TblOrganization;
import com.huabo.system.oracle.entity.TblYyUserQuery;
import com.hbfk.util.PageInfo;
import com.huabo.system.service.impl.SysConfig;

import java.math.BigDecimal;

public class TblYyOrgDepositMapperSqlConifg {
	
	
	public String selectListByPageInfo(PageInfo<TblYyUserQuery> pageInfo) {
		TblYyUserQuery yuq = pageInfo.getCondition();
		StringBuffer sqlSb = new StringBuffer("SELECT * FROM (SELECT BUDGET.*,ROWNUM RN FROM (Select uq.*,s.REALNAME FROM TBL_YY_USER_QUERY uq " +
				" LEFT JOIN TBL_ORGANIZATION o on uq.ORGID = o.ORGID " +
				" LEFT JOIN TBL_STAFF s ON uq.QUERYSTAFF = s.STAFFID WHERE uq.ORGID ="+yuq.getOrgid());
		if(yuq.getStaffid() != null){
			sqlSb.append(" AND QUERYSTAFF = '"+yuq.getStaffid()+"'");
		}
		if(yuq.getReportName() != null){
			yuq.setReportName("%"+yuq.getReportName()+"%");
			sqlSb.append(" AND uq.REPORTNAME LIKE '%"+yuq.getReportName()+"%'");
		}
		sqlSb.append(" ORDER BY uq.QUERYTIME DESC ) BUDGET WHERE rownum <= "+(pageInfo.getCurrentPage()*pageInfo.getPageSize())+" ) WHERE RN > "+pageInfo.getCurrentRecord());
		String sql = sqlSb.toString();
		return sql;
	}
	
	public String selectCountByPageInfo(PageInfo<TblYyUserQuery> pageInfo) {
		TblYyUserQuery yuq = pageInfo.getCondition();
		String hqlCount = "Select COUNT(*) FROM TBL_YY_USER_QUERY uq " +
				" LEFT JOIN TBL_ORGANIZATION o on uq.ORGID = o.ORGID " +
				" LEFT JOIN TBL_STAFF s ON uq.QUERYSTAFF = s.STAFFID WHERE uq.ORGID = '"+yuq.getOrgid()+"'";
		if(yuq.getStaffid() != null){
			hqlCount+=" AND QUERYSTAFF ='"+yuq.getStaffid()+"'   ";
		}
		if(yuq.getReportName() != null){
			yuq.setReportName("%"+yuq.getReportName()+"%");
			hqlCount += " AND uq.REPORTNAME LIKE '%"+ yuq.getReportName() +"%'";
		}
		return hqlCount;
	}
	

	

	
}
